package com.rop.znyx.home.service.impl;

import com.rop.znyx.home.service.HomeService;
import com.rop.znyx.model.product.Category;
import com.rop.znyx.model.product.SkuInfo;
import com.rop.znyx.model.search.SkuEs;
import com.rop.znyx.product.ProductFeignClient;
import com.rop.znyx.search.SearchFeignClient;
import com.rop.znyx.user.UserFeignClient;
import com.rop.znyx.vo.user.LeaderAddressVo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA
 * User: Rop
 * Date: 2023/7/19
 * Time: 14:37
 * Description:
 */

@Service
@RequiredArgsConstructor
public class HomeServiceImpl implements HomeService {

    private final UserFeignClient userFeignClient;

    private final ProductFeignClient productFeignClient;

    private final SearchFeignClient searchFeignClient;


    /**
     * 首页数据
     */
    @Override
    public Map<String, Object> home(Long userId) {
        Map<String, Object> map = new HashMap<>();

        // 1.根据userId获取当前登录用户的提货地址信息
        // 通过远程调用service-user模块接口
        LeaderAddressVo leaderAddressVo = userFeignClient.getUserAddressByUserId(userId).getData();
        map.put("leaderAddressVo", leaderAddressVo);

        // 2.获取所有sku的分类信息
        // 远程调用service-product模块接口
        List<Category> categoryList = productFeignClient.findAllCategoryList().getData();
        map.put("categoryList", categoryList);



        // 3.获取新人专享商品
        // 远程调用service-product模块接口
        List<SkuInfo> newPersonSkuInfoList =  productFeignClient.findNewPersonSkuInfoList().getData();
        map.put("newPersonSkuInfoList", newPersonSkuInfoList);

        // 4.获取上架中的爆款商品
        // 远程调用service-search模块接口
        List<SkuEs> hotSkuList = searchFeignClient.findHotSkuList().getData();
        map.put("hotSkuList", hotSkuList);
        // 5.封装获取的数据到map集合中，返回

        return map;
    }
}
